package com.zj.osm.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * @ProjectName: OsmDroid
 * @Package: com.zj.osm.utils
 * @Author: jiang zhu
 * @Date: 2019/12/11 16:36
 */
public class XmlUtils {

    /**
     * xml文件转换字符串
     *
     * @param path 文件路径
     * @return /
     */
    public static String xmlFileToStr(String path) {
        String xmlString;
        byte[] strBuffer = null;
        InputStream in;
        int flen;
        File xmlfile = new File(path);
        try {
            in = new FileInputStream(xmlfile);
            flen = (int) xmlfile.length();
            strBuffer = new byte[flen];
            in.read(strBuffer, 0, flen);
            in.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        assert strBuffer != null;
        xmlString = new String(strBuffer); //构建String时，可用byte[]类型，
        return xmlString;
    }

}
